﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MM.Common.Base;
using MM.Common.DBBase;

namespace MM.Common.Support
{
    public partial class UCDoctorInfo : UserControl
    {
        public UCDoctorInfo()
        {
            InitializeComponent();
        }

        public bool Delete(int empid)
        {
            bool flag = true;
            try
            {
                DataParamCol parms = new DataParamCol(new DataParam[] { new InputDataParam("empid", empid) });
                string commandtext = "DELETE FROM MXHLY_DIC_DOCTOR_INFO WHERE EMP_ID = :empid";
                if (SystemInfo.DbData.ExecuteSql(commandtext, parms) < 0)
                {
                    flag = false;
                }
            }
            catch
            {
                flag = false;
            }
            return flag;
        }

        public void DisplayInfo(int empid)
        {
            DataTable dt = new DataTable();
            DataParamCol parm = new DataParamCol(new DataParam[] { new InputDataParam("empid", empid) });
            SystemInfo.DbData.Retrieve("SELECT * FROM MXHLY_DIC_DOCTOR_INFO WHERE EMP_ID = :empid", parm, ref dt);
            if (dt.Rows.Count == 1)
            {
                string str = Converts.ConverToString(dt.Rows[0]["PRESCRIPTION"], "NNN");
                this.ckCfq_y.Checked = str.IndexOf("Y") != -1;
                this.ckCfq_z.Checked = str.IndexOf("Z") != -1;
                this.ckCfq_c.Checked = str.IndexOf("C") != -1;
                this.ckMzf.Checked = Converts.ConverToString(dt.Rows[0]["NARCOTIC"], "N") == "Y";
                this.ckJsf.Checked = Converts.ConverToString(dt.Rows[0]["PSYCHOTROPIC"], "N") == "Y";
                this.ckDpf.Checked = Converts.ConverToString(dt.Rows[0]["POISON"], "N") == "Y";
                this.ckPsf.Checked = Converts.ConverToString(dt.Rows[0]["SKIN_TEST"], "N") == "Y";
                this.seKss.FieldValue = Converts.ConverToInt(dt.Rows[0]["ANTIBIOTIC_LEVELS"], 0);
            }
            else
            {
                this.ckCfq_y.Checked = false;
                this.ckCfq_z.Checked = false;
                this.ckCfq_c.Checked = false;
                this.ckMzf.Checked = false;
                this.ckJsf.Checked = false;
                this.ckDpf.Checked = false;
                this.ckPsf.Checked = false;
            }
        }

        public void New()
        {
            this.ckCfq_y.Checked = false;
            this.ckCfq_z.Checked = false;
            this.ckCfq_c.Checked = false;
            this.ckMzf.Checked = false;
            this.ckJsf.Checked = false;
            this.ckDpf.Checked = false;
            this.ckPsf.Checked = false;
        }

        public bool Save(int empid, bool isexist)
        {
            bool flag = true;
            try
            {
                string paramValue = (this.ckCfq_y.Checked ? "Y" : string.Empty) + (this.ckCfq_z.Checked ? "Z" : string.Empty) + (this.ckCfq_c.Checked ? "C" : string.Empty);
                string str2 = this.ckMzf.Checked ? "Y" : "N";
                string str3 = this.ckJsf.Checked ? "Y" : "N";
                string str4 = this.ckDpf.Checked ? "Y" : "N";
                string str5 = this.ckPsf.Checked ? "Y" : "N";
                int num = Convert.ToInt32(this.seKss.FieldValue);
                DataParamCol parms = new DataParamCol(new DataParam[] { new InputDataParam("empid", empid) });
                string commandtext = "DELETE FROM MXHLY_DIC_DOCTOR_INFO WHERE EMP_ID = :empid";
                if (SystemInfo.DbData.ExecuteSql(commandtext, parms) < 0)
                {
                    SystemInfo.DbData.TransactionRollback();
                    return false;
                }
                if (isexist)
                {
                    commandtext = "INSERT INTO MXHLY_DIC_DOCTOR_INFO (EMP_ID ,PRESCRIPTION ,NARCOTIC ,PSYCHOTROPIC ,POISON ,SKIN_TEST ,ANTIBIOTIC_LEVELS) \r\n   VALUES (:empid ,:prescription ,:narcotic ,:psychotropic ,:poison ,:skin_test ,:antibiotic_levels) ";
                    parms = new DataParamCol(new DataParam[] { new InputDataParam("empid", empid), new InputDataParam("prescription", paramValue), new InputDataParam("narcotic", str2), new InputDataParam("psychotropic", str3), new InputDataParam("poison", str4), new InputDataParam("skin_test", str5), new InputDataParam("antibiotic_levels", num) });
                    if (SystemInfo.DbData.ExecuteSql(commandtext, parms, 1) != 1)
                    {
                        SystemInfo.DbData.TransactionRollback();
                        flag = false;
                    }
                }
            }
            catch
            {
            }
            return flag;
        }

        public void SetEnable(bool isedit)
        {
            this.ckCfq_y.Properties.ReadOnly = !isedit;
            this.ckCfq_z.Properties.ReadOnly = !isedit;
            this.ckCfq_c.Properties.ReadOnly = !isedit;
            this.ckMzf.Properties.ReadOnly = !isedit;
            this.ckJsf.Properties.ReadOnly = !isedit;
            this.ckDpf.Properties.ReadOnly = !isedit;
            this.ckPsf.Properties.ReadOnly = !isedit;
        }
    }
}
